/**************************************************************
 * Ben Stephenson       07025656
 * Mark Renney          07010390
 * Laurie Potts         07009314
 * Michael Peeke-Vout   07014312
 *
 * CM0034 Industrial Case Project
 * Conveyor Belt
 * messages.h
 * 28/02/2011
 * Updated - 14/03/11 
 **************************************************************/
#ifndef __MESSAGES_H
#define __MESSAGES_H

#include <stdbool.h>
#include <can.h>
#include <interface.h>
#include <leds.h>



/**************************************
 *************** DEFINES***************
 *^z***********************************/
// Msg identifiers and node identifiers
#define     ID_ALLNODES   0
#define     ID_CONTROLP   1
#define     ID_ARM1       2
#define     ID_CONVEYOR   3
#define     ID_ARM2       4

#define     MSG_EMERG_STOP     10
#define     MSG_PAUSE          15
#define     MSG_RESUME         20

#define     MSG_STOP                25
#define     MSG_CON_SENS1_STAT_REQ  30
#define     MSG_CON_SENS2_STAT_REQ  35
#define     MSG_PAD_SENS1_STAT_REQ  40
#define     MSG_PAD_SENS2_STAT_REQ  45

#define     MSG_PICKUP_DEPOSIT_DONE 50

#define     MSG_SENS1_EMPTY    55
#define     MSG_SENS1_FULL     60
#define     MSG_SENS2_EMPTY    65
#define     MSG_SENS2_FULL     70

#define     MSG_ACKNOLEDGE     75
#define     MSG_READY          80

// For message filtering purposes
#define     MSG_COMPONENT      MSG_STOP


// Change this to your component
#define     MY_ID              ID_CONVEYOR


// Did we read a message from the CAN or not?
#define     NO_MSG   0
#define     MSG      1

/*z^***********************************/


/**************************************
 ************* PROTOTYPES *************
 *^z***********************************/

typedef struct 
{
  uint32_t targetID;
  uint32_t originatorID;
  uint32_t content;
} messageData_t;

bool writeMsgToCan(messageData_t *);
bool readMsgFromCan(messageData_t *);
bool sendACK(uint8_t);
void getLastMsg(messageData_t *, int);
/*z^***********************************/
/******************************************* EOF *************************************************/
#endif
